package com.pai4j.ugc.service.chain;
import com.pai4j.common.util.IPAddressUtil;
import com.pai4j.domain.vo.response.IpLocationResponseVO;
import com.pai4j.domain.vo.response.moment.MomentVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;


@Slf4j
@Component
public class MomentIpAddressHandler implements MomentPublishHandler {


    @Override
    public void handle(MomentVO moment, MomentPublishHandlerChain chain) throws Exception {

        IpLocationResponseVO address = IPAddressUtil.location(moment.getIp());
        if (address != null) {
            moment.setIpAddress(address.getProvince());
        }
        chain.handle(moment, chain);
    }
}
